﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;




namespace Model.Borrowers
{
    public class Borrower : BaseValidatableObject
    {
        public Guid Id {get;set;}
        public DateTime BirthDate {get;set;}
        [Required(ErrorMessage = "A borrower must have a first name")]
        [StringLength(50,ErrorMessage = "A borrower's first name is limited to 50 characters")]
        public string FirstName {get;set;}
        [Required(ErrorMessage = "A borrower must have a last name")]
        [StringLength(50, ErrorMessage = "A borrower's last name is limited to 50 characters" )]
        public string LastName {get;set;}
        public override IEnumerable<ValidationResult> CustomValidate(ValidationContext validationContext)
        {
            int age = DateTime.Now.Year - BirthDate.Year;
            if (age < 18)
            {
                yield return new ValidationResult("A borrower must be over 18 years of age", new string[] { "Age" });
            }
        }
    }
}
